package com.csw.pojo;

import com.csw.GameFrame;
import lombok.Data;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * @author A
 * @version 1.0
 * @description: 牌
 * @date 2022/11/28 23:57
 */

public class Brand extends Component{

    private String name;
    //是否置灰
    private Boolean isGray;

    private Image image;

    private Image garyImage;

    private Integer x;
    private Integer y;

    private Integer width;
    private Integer height;

    //和cell的链式关系
    private Cell cell;
    public Brand(String name){
        this.name=name;
        this.image=Toolkit.getDefaultToolkit().getImage("imgs\\"+name+".png");
        this.garyImage=Toolkit.getDefaultToolkit().getImage("imgs\\"+name+"_gray.png");
        this.isGray=false;
        this.width=50;
        this.height=50;
        this.x=0;
        this.y=0;

        this.addMouseListener(new MouseAdapter() {
            //Event 事件发生的上下文对象
            @Override
            public void mouseClicked(MouseEvent e) {
                //获得当前组件
                Brand brand = (Brand) e.getSource();

                if (brand.getGray()){
                    return;
                }else {
                    //通关父容器删掉自己
                    //brand.getParent().remove(brand);
                    Box box = new Box();
                    box.setBrandList(brand);
                    //还要将cell的状态置0
                    Cell cell = brand.getCell();
                    cell.setState(0);
                    cell.setBrand(brand);
                    //还要刷新一下
                    GameFrame.map.compareAll();
                }


            }
        });
    }

    @Override
    public void paint(Graphics g) {
        if (this.isGray){
            g.drawImage(this.garyImage, this.x, this.y, null);
        }else {
            g.drawImage(this.image, this.x, this.y, null);
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getGray() {
        return isGray;
    }

    public void setGray(Boolean gray) {
        isGray = gray;
    }

    public Image getImage() {
        return image;
    }

    public void setImage(Image image) {
        this.image = image;
    }

    public Image getGaryImage() {
        return garyImage;
    }

    public void setGaryImage(Image garyImage) {
        this.garyImage = garyImage;
    }

    public Cell getCell() {
        return cell;
    }

    public void setCell(Cell cell) {
        this.cell = cell;
    }

    @Override
    public String toString() {
        return "Brand{" +
                "name='" + name + '\'' +
                ", isGray=" + isGray +
                ", image=" + image +
                ", garyImage=" + garyImage +
                ", x=" + x +
                ", y=" + y +
                ", width=" + width +
                ", height=" + height +
                '}';
    }
}
